package com.example.demo.controller;


import com.example.demo.pojo.PlannerResult;
import com.example.demo.service.UserService;
import com.example.demo.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
public class AuthorController {

    @Autowired
    UserService userService;

    /*
    @GetMapping("/login/{account}/{password}")
    public PlannerResult<String> login(@PathVariable("account") String account, @PathVariable("password") String password) {
        return userService.login(account,password);
    }
     */

    @GetMapping("/find/password")
    public PlannerResult<String> find_password(@RequestParam("account") String account,
                                               @RequestParam("password") String password,
                                               @RequestParam("code") String code) {
        return userService.find_password(account,password,code);
    }

    /*

     */
    @PostMapping("/login")
    public PlannerResult<UserVo> login(@RequestParam("account") String account, @RequestParam("password") String password) {
        return userService.login(account,password);
    }



    @PostMapping("/register")
    public PlannerResult<String> register(@RequestBody UserVo user) {
        return userService.register(user);
    }

    @GetMapping("/verification/code")
    public PlannerResult<String> sendEmailVerificationCode(@RequestParam("identifier") String identifier,
                                                           @RequestParam("type") String type) {
        if (type.equals("email")) {
            return userService.sendEmailVerificationCode(identifier);
        }
        if (type.equals("phone")) {
            return userService.sendPhoneVerificationCode(identifier);
        }
        return PlannerResult.error("发送验证码失败");
    }
}
